package codewar;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class TestSell {
    public static final String A = "25";
    public static final String B = "50";
    public static final String C = "100";
    public static final String YES = "YES";
    public static final String NO = "NO";


    private static Map<String, Integer> map = new HashMap();

    public TestSell() {
    }

    public static void main(String[] args) {

        Tickets(new int[]{25, 25, 25, 25, 50, 100, 50}, 1);


    }

    public static String Tickets(int[] peopleInLine, int tpye) {
        System.out.println(Arrays.toString(peopleInLine));
        //Your code is here...
        String result = "DE";
        int length = peopleInLine.length;
        if (length == 1) {
            result = "YES";
            return result;
        }
        for (int i = 0; i < length; i++) {
            //
            int cur = peopleInLine[i];
            switch (cur) {
                case 25:
                    result = YES;
                    putValue(A);
                    break;
                case 50:
                    int num = map.get(A);
                    if (num >= 1) {
                        result = "YES";
                    }
                    removeValue(A);
                    //
                    putValue(B);
                    break;
                case 100:
                    int va = judgeEnough75();
                    switch (va) {
                        case 0:
                            result = NO;
                            break;
                        case 1:
                            result = YES;
                            removeValue(A);
                            removeValue(A);
                            removeValue(A);

                            break;
                        case 2:
                            result = YES;
                            removeValue(B);
                            removeValue(A);
                            break;
                        case 3:
                            if (tpye==1){
                                // do Something
                                result = YES;
                                removeValue(A);
                                removeValue(A);
                                removeValue(A);
                            }else {
                                result = YES;
                                removeValue(B);
                                removeValue(A);
                            }


                            break;

                    }
                    putValue(C);
                    break;
            }

        }
        if (result==NO){
            result=Tickets(peopleInLine, 2);
        }
        System.out.println(result);
        return result;
    }

    // 0  ,1(),2, 3;
    public static int judgeEnough75() {
        int value = 0;
        if (map.get(B) >= 1 && map.get(A) >= 1) {
            value = value + 2;
        }
        if (map.get(A) >= 3) {
            value = value + 1;
        }
        return value;
    }

    public static void putValue(String arg) {

        if (map.get(arg) != null) {
            int numb = map.get(arg);
            map.put(arg, numb + 1);
        } else {
            map.put(arg, 1);
        }
    }

    public static void removeValue(String arg) {
        if (map.get(arg) != null) {
            int numb = map.get(arg);
            if (numb >= 1) {
                map.put(arg, numb - 1);
            }
        }

    }
}
